package cn.yh.register.user.controller;

import cn.yh.register.common.result.Result;
import cn.yh.register.model.user.UserInfo;
import cn.yh.register.user.service.UserInfoService;
import cn.yh.register.vo.user.UserInfoQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Api(tags = "用户管理接口")
@RestController
@RequestMapping("/admin/user")
public class UserController {

    @Autowired
    UserInfoService userInfoService;

    @ApiOperation("分页查询用户列表")
    @GetMapping("/{page}/{limit}")
    public Result<Page<UserInfo>> getPageList(@PathVariable Integer page,@PathVariable("limit") Integer size, UserInfoQueryVo queryVo){

        Page<UserInfo> userInfoPage = userInfoService.findPageList(page, size, queryVo);
        return Result.ok(userInfoPage);
    }

    @ApiOperation(value = "锁定")
    @GetMapping("lock/{userId}/{status}")
    public Result<?> lock(@PathVariable("userId") Long userId,
                         @PathVariable("status") Integer status){
        userInfoService.lock(userId,status);
        return Result.ok();
    }

    @ApiOperation(value = "获取用户详情")
    @GetMapping("/show/{userId}")
    public Result<Map<String, Object>> show (@PathVariable Long userId){
        Map<String, Object> map = userInfoService.getUser(userId);
        return Result.ok(map);
    }

    @ApiOperation(value ="用户审批")
    @GetMapping("approval/{userId}/{authStatus}")
    public Result<?> approval(@PathVariable Long userId,
                             @PathVariable Integer authStatus){
        userInfoService.approve(userId,authStatus);
        return Result.ok();
    }
}
